package com.liy.supercloud.ssoclient.security.jwt;

import com.liy.framework.common.exception.NotAuthorizationException;
import com.liy.framework.common.extvo.LoginInfo;
import com.liy.framework.common.jwt.JWTHelper;
import io.jsonwebtoken.ExpiredJwtException;
import io.jsonwebtoken.SignatureException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.Assert;

@Configuration
public class JwtTokenService {

    @Autowired
    private UserAuthConfig userAuthConfig;


    public LoginInfo getInfoFromToken(String token) throws Exception {
        try {
            Assert.notNull(token, "401: User token is null!");
            return JWTHelper.getInfoFromToken(token, this.userAuthConfig.getPubKeyByte());
        } catch (ExpiredJwtException var3) {
            throw new NotAuthorizationException("User token expired!");
        } catch (SignatureException var4) {
            throw new NotAuthorizationException("User token signature error!");
        } catch (IllegalArgumentException var5) {
            throw new NotAuthorizationException("User token is null or empty!");
        }
    }
}
